<template>
	<div class="app-container">
		<el-card class="box-card">
			<div slot="header" class="box-card-header clearfix">
				<span>基本设置</span>
			</div>
			<el-row style="display: ">
				<el-form :inline="true">
					<el-form-item label="HG地址：" label-width="100px">
						<el-input v-model="setting.hga_url" placeholder="请输入HG网址"></el-input>
					</el-form-item>
					<el-form-item label="账号/密码：">
						<el-input v-model="setting.hga_user_name" placeholder="请输入用户" style="width: 48%"></el-input>
						<el-input v-model="setting.hga_password" placeholder="请输入密码" style="width: 48%"></el-input>
					</el-form-item>
					<el-form-item label="刷新间隔：">
						<el-input v-model="setting.hga_api_time" placeholder="请输入" style="width: 60%">
							<template slot="append">秒</template>
						</el-input>
					</el-form-item>
				</el-form>
			</el-row>
			<el-row style="display: none">
				<el-form :inline="true">
					<el-form-item label="u1368地址：" label-width="100px">
						<el-input v-model="setting.u1368_url" placeholder="请输入u1368网址"></el-input>
					</el-form-item>
					<el-form-item label="账号/密码：">
						<el-input v-model="setting.u1368_user_name" placeholder="请输入用户" style="width: 48%"></el-input>
						<el-input v-model="setting.u1368_password" placeholder="请输入密码" style="width: 48%"></el-input>
					</el-form-item>
					<el-form-item label="刷新间隔：">
						<el-input v-model="setting.u1368_api_time" placeholder="请输入" style="width: 60%">
							<template slot="append">秒</template>
						</el-input>
					</el-form-item>
				</el-form>
			</el-row>
			<el-row>
				<el-form :inline="true">
					<el-form-item label="平博地址：" label-width="100px">
						<el-input v-model="setting.ps_url" placeholder="请输入平博网址"></el-input>
					</el-form-item>
					<el-form-item label="账号/密码：">
						<el-input v-model="setting.ps_user_name" placeholder="请输入用户" style="width: 48%"></el-input>
						<el-input v-model="setting.ps_password" placeholder="请输入密码" style="width: 48%"></el-input>
					</el-form-item>
					<el-form-item label="刷新间隔：">
						<el-input v-model="setting.ps_api_time" placeholder="请输入" style="width: 60%">
							<template slot="append">秒</template>
						</el-input>
					</el-form-item>
				</el-form>
			</el-row>
		</el-card>
		<div style="height: 20px;"></div>
		<el-card class="box-card">
			<div slot="header" class="box-card-header clearfix">
				<span>HG下注设置</span>
			</div>
			<el-row>
				<el-form :inline="true">
					<el-form-item label="">
						<el-switch
							v-model="setting.has_bet_server"
							active-text="下注类型服务端分配">
						</el-switch>
						<el-checkbox :disabled="setting.has_bet_server" v-for="item in setting.bet_type_list" :key="item.type" :label="item.label" v-model="item.checked" border></el-checkbox>
					</el-form-item>
					<br/>
					<el-form-item label="打单类型：">
						<el-switch
							v-model="setting.open_today_game"
							active-text="赛前">
						</el-switch>
						<span style="width: 20px;display: inline-block"></span>
						<el-switch
							v-model="setting.open_doing_game"
							active-text="滚球">
						</el-switch>
					</el-form-item>
					<el-form-item label="每天成功几单后退出APP">
						<el-input v-model="setting.suc_order_max_count" placeholder="请输入数量" />
					</el-form-item>
					<br/>
					<el-form-item label="HGA下注金额：">
						<el-input v-model="setting.bet_amount" placeholder="请输入金额">
							<template slot="append">CNY</template>
						</el-input>
					</el-form-item>
					<el-form-item label="PS下注金额：">
						<el-input v-model="setting.ps_bet_amount" placeholder="请输入金额">
							<template slot="append">CNY</template>
						</el-input>
					</el-form-item>
					<el-form-item label="随机数">
						<el-input v-model="setting.bet_random_max_number" placeholder="随机数">
						</el-input>
					</el-form-item>
					<el-form-item label="随机金额单位">
						<el-input v-model="setting.bet_random_amount" placeholder="随机金额单位">
							<template slot="append">CNY</template>
						</el-input>
					</el-form-item>
				</el-form>
			</el-row>
		</el-card>
		<div style="height: 20px;"></div>
		<el-card class="box-card">
			<div slot="header" class="box-card-header clearfix">
				<span>通用下注设置</span>
			</div>
			<el-row>
				<el-form :inline="true">
					<el-form-item label="赛前时间：">
						<el-row>
							<el-col :span="11">
								<el-input v-model="setting.game_time_start" placeholder="开始时间" ><template slot="append">分</template></el-input>
							</el-col>
							<el-col :span="2" style="text-align: center"> - </el-col>
							<el-col :span="11">
								<el-input v-model="setting.game_time_end" placeholder="结束时间" ><template slot="append">分</template></el-input>
							</el-col>
						</el-row>
					</el-form-item>
					<br />
					<el-form-item label="HG水位范围：">
						<el-row>
							<el-col :span="11">
								<el-input v-model="setting.hga_odds_min" placeholder="最低水位" ></el-input>
							</el-col>
							<el-col :span="2" style="text-align: center"> - </el-col>
							<el-col :span="11">
								<el-input v-model="setting.hga_odds_max" placeholder="最高水位"></el-input>
							</el-col>
						</el-row>
					</el-form-item>
					<el-form-item label="平博水位范围：">
						<el-row>
							<el-col :span="11">
								<el-input v-model="setting.ps_odds_min" placeholder="最低水位" ></el-input>
							</el-col>
							<el-col :span="2" style="text-align: center"> - </el-col>
							<el-col :span="11">
								<el-input v-model="setting.ps_odds_max" placeholder="最高水位"></el-input>
							</el-col>
						</el-row>
					</el-form-item>
					<br />
					
					<el-form-item label="投注间隔：">
						<el-input v-model="setting.bet_interval_time" placeholder="请输入秒数" ><template slot="append">秒</template></el-input>
					</el-form-item>
					<el-form-item label="失败重试：">
						<el-input v-model="setting.bet_error_max_count" placeholder="请输入次数" ><template slot="append">次</template></el-input>
					</el-form-item>
					<el-form-item label="单注限额不低于：">
						<el-input v-model="setting.bet_min_amount" placeholder="单注限额不低于" ></el-input>
					</el-form-item>
					<br/>
					<el-form-item label="平皇合水值低于：">
						<el-input v-model="setting.bet_count_odds" placeholder="平皇合水值低于" ></el-input>
					</el-form-item>
					<el-form-item label="同一盘口最多下注次数：">
						<el-input v-model="setting.bet_max_count" placeholder="请输入次数" ><template slot="append">次</template></el-input>
					</el-form-item>
					<el-form-item label="最低下注水位：">
						<el-input v-model="setting.bet_min_odds" placeholder="请输入最低水位" ></el-input>
					</el-form-item>
					<el-form-item label="平博水位差：">
						<el-row>
							<el-col :span="11">
								<el-input v-model="setting.ps_diff_odds_min" placeholder="范围" ></el-input>
							</el-col>
							<el-col :span="2" style="text-align: center"> - </el-col>
							<el-col :span="11">
								<el-input v-model="setting.ps_diff_odds_max" placeholder="范围"></el-input>
							</el-col>
						</el-row>
					</el-form-item>
					
					<br/>
					<el-form-item label="User-Agent：">
						<el-select v-model="setting.bet_user_agent" placeholder="请选择">
							<el-option
								v-for="item in bet_user_agent_list"
								:key="item.value"
								:label="item.label"
								:value="item.value">
							</el-option>
						</el-select>
						<!--						<el-input v-model="setting.bet_user_agent" placeholder="User-Agent" ></el-input>-->
					</el-form-item>
					<br/>
<!--					<el-form-item label="平博升水位：">
						<el-input v-model="setting.ps_odds_add" placeholder="要加多少赔率" ></el-input>
					</el-form-item>-->
					<!--					<el-form-item label="HGA升水位：">
											<el-input v-model="setting.hga_odds_add" placeholder="要加多少赔率" ></el-input>
										</el-form-item>-->
				</el-form>
			</el-row>
		</el-card>
		<div style="height: 20px;"></div>
		<el-card class="box-card">
			<div slot="header" class="box-card-header clearfix">
				<span>滚球下单设置</span>
			</div>
			<el-row>
				<el-form :inline="true">
					<el-form-item label="滚球时间：">
						<el-row>
							<el-col :span="11">
								<el-input v-model="setting.doing_game_time_start" placeholder="开始时间" ><template slot="append">分</template></el-input>
							</el-col>
							<el-col :span="2" style="text-align: center"> - </el-col>
							<el-col :span="11">
								<el-input v-model="setting.doing_game_time_end" placeholder="结束时间" ><template slot="append">分</template></el-input>
							</el-col>
						</el-row>
					</el-form-item>
					<br/>
					<el-form-item label="HG水位范围：">
						<el-row>
							<el-col :span="11">
								<el-input v-model="setting.doing_hga_odds_min" placeholder="最低水位" ></el-input>
							</el-col>
							<el-col :span="2" style="text-align: center"> - </el-col>
							<el-col :span="11">
								<el-input v-model="setting.doing_hga_odds_max" placeholder="最高水位"></el-input>
							</el-col>
						</el-row>
					</el-form-item>
					<el-form-item label="平博水位范围：">
						<el-row>
							<el-col :span="11">
								<el-input v-model="setting.doing_ps_odds_min" placeholder="最低水位" ></el-input>
							</el-col>
							<el-col :span="2" style="text-align: center"> - </el-col>
							<el-col :span="11">
								<el-input v-model="setting.doing_ps_odds_max" placeholder="最高水位"></el-input>
							</el-col>
						</el-row>
					</el-form-item>
					<el-form-item label="单注限额不低于：">
						<el-input v-model="setting.doing_bet_min_amount" placeholder="单注限额不低于" ></el-input>
					</el-form-item>
					<el-form-item label="最低下注水位：">
						<el-input v-model="setting.doing_bet_min_odds" placeholder="请输入最低水位" ></el-input>
					</el-form-item>
					<br/>
					<el-form-item label="HGA下注金额：">
						<el-input v-model="setting.doing_bet_amount" placeholder="请输入金额">
							<template slot="append">CNY</template>
						</el-input>
					</el-form-item>
					<el-form-item label="PS下注金额：">
						<el-input v-model="setting.doing_ps_bet_amount" placeholder="请输入金额">
							<template slot="append">CNY</template>
						</el-input>
					</el-form-item>
					<el-form-item label="平皇合水值低于：">
						<el-input v-model="setting.doing_bet_count_odds" placeholder="平皇合水值低于" ></el-input>
					</el-form-item>
					<el-form-item label="平博水位差：">
						<el-row>
							<el-col :span="11">
								<el-input v-model="setting.doing_ps_diff_odds_min" placeholder="范围" ></el-input>
							</el-col>
							<el-col :span="2" style="text-align: center"> - </el-col>
							<el-col :span="11">
								<el-input v-model="setting.doing_ps_diff_odds_max" placeholder="范围"></el-input>
							</el-col>
						</el-row>
					</el-form-item>
				</el-form>
			</el-row>
		</el-card>
				<div style="height: 20px;"></div>
		<el-card class="box-card" style="">
			<div slot="header" class="box-card-header clearfix">
				<span>协议下单设置</span>
			</div>
			<el-row>
				<el-form :inline="true">
					<el-form-item label="随机延迟下注：">
						<el-input style="width: 150px;" v-model="setting.agreement_bet_time_start" placeholder="请输入时间" ><template slot="append">秒</template></el-input> - <el-input  style="width: 150px;"  v-model="setting.agreement_bet_time_end" placeholder="请输入时间" ><template slot="append">秒</template></el-input>
					</el-form-item>
					<el-form-item label="最低下注水位：">
						<el-input v-model="setting.agreement_bet_min_odds" placeholder="请输入最低水位" ></el-input>
					</el-form-item>
					<br/>
					<el-form-item label="下注金额设置：">
						<div style="padding-bottom: 10px;" v-for="item in setting.agreement_amount_list">
							<el-checkbox v-model="item.checked" /> <el-input v-model="item.range_start" style="width: 150px;margin-left: 5px;" placeholder="起始金额" /> <span style="padding:0 5px;">-</span> <el-input v-model="item.range_end" style="width: 150px;" placeholder="目标金额" /> <el-input v-model="item.amount" style="width: 150px;margin-left: 10px;" placeholder="下注金额" />
						</div>
					</el-form-item>
					<br/>
				</el-form>
			</el-row>
		</el-card>
		<div class="setting-button">
			<el-button type="primary" @click.stop="saveSetting" blank round>保存设置</el-button>
		</div>
	</div>
</template>

<script>
import { configStore } from "@/store/config";
import {ipcRenderer} from "electron";
const validator = require('validator');
let storeConfig = configStore();


let url_keys = [
	{
		'key':'hga_url',
		'desc': 'HGA域名',
	},
	{
		'key':'ps_url',
		'desc': 'PS域名'
	}
];
let int_keys = [
	{
		'key':'bet_amount',
		'desc': '下注金额'
	},
	{
		'key': 'game_time_start',
		'desc': '赛中时间开始'
	},
	{
		'key': 'game_time_end',
		'desc': '赛中时间结束'
	},
	{
		'key': 'bet_interval_time',
		'desc': '下单间隔秒数'
	},
	{
		'key': 'bet_error_max_count',
		'desc': '失败重试次数'
	},
	{
		'key': 'bet_max_count',
		'desc': '最多补单次数'
	},
	{
		'key': 'bet_min_amount',
		'desc': '限额最低金额'
	},
	{
		'key': 'agreement_bet_time_start',
		'desc': '随机下注秒数'
	},
	{
		'key': 'agreement_bet_time_end',
		'desc': '随机下注秒数'
	},
];
let number_keys = [
	{
		'key':'ps_odds_min',
		'desc': '最低水位'
	},
	{
		'key': 'ps_odds_max',
		'desc': '最高水位'
	},
	{
		'key':'hga_odds_min',
		'desc': '最低水位'
	},
	{
		'key': 'hga_odds_max',
		'desc': '最高水位'
	},
	{
		'key': 'bet_min_odds',
		'desc': '下单水位'
	},
	{
		'key': 'bet_count_odds',
		'desc': '合水值'
	}
];

export default {
	data() {
		return {
			bet_user_agent_list:[
				{
					"label": "iPhone 13",
					"value": "Mozilla/5.0 (iPhone; CPU iPhone OS 15_0 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/15.0 Mobile/15E148 Safari/604.1"
				},
				{
					"label":"iPhone 14",
					"value": "Mozilla/5.0 (iPhone; CPU iPhone OS 16_0 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/16.0 Mobile/15E148 Safari/604.1"
				},
				{
					"label":"iPhone 15",
					"value": "Mozilla/5.0 (iPhone; CPU iPhone OS 17_0 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/17.0 Mobile/15E148 Safari/604.1"
				},
				{
					"label": "小米 11",
					"value": "Mozilla/5.0 (Linux; Android 12; MI 12 Build/SKQ1.211006.001; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/96.0.4664.45 Mobile Safari/537.36"
				},
				{
					"label": "小米 10",
					"value": "Mozilla/5.0 (Linux; Android 10; Mi 10 Build/QKQ1.190828.002) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.149 Mobile Safari/537.36"
				},
				{
					"label": "小米 9",
					"value": "Mozilla/5.0 (Linux; Android 10; Mi 9 Build/QKQ1.190828.002) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.149 Mobile Safari/537.36"
				},
				{
					"label": "红米 note 10",
					"value": "Mozilla/5.0 (Linux; Android 11; Redmi Note 10 Build/RKQ1.200628.002; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/88.0.4324.150 Mobile Safari/537.36"
				},
				{
					"label": "红米 note 8",
					"value": "Mozilla/5.0 (Linux; Android 9; Redmi Note 8 Build/PPR1.180610.011) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.149 Mobile Safari/537.36"
				},
				{
					"label": "红米 K30",
					"value": "Mozilla/5.0 (Linux; Android 10; Redmi K30 Build/QKQ1.190828.002) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.149 Mobile Safari/537.36"
				},
				{
					"label": "华为 Mate 30",
					"value": "Mozilla/5.0 (Linux; Android 10; HUAWEI Mate 30 Build/HUAWEIMate30) AppleWebKit/537.36 (KHTML, like Gecko) Version/10.0.0.201 Mobile Safari/537.36",
				},
				{
					"label": "华为 Nova 5",
					"value": "Mozilla/5.0 (Linux; Android 9; HUAWEI Nova 5 Build/HUAWEINova5) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/80.0.3987.149 Mobile Safari/537.36"
				},
				{
					"label": "华为 P40",
					"value": "Mozilla/5.0 (Linux; Android 10; HUAWEI P40 Build/HUAWEIP40) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/80.0.3987.149 Mobile Safari/537.36"
				},
				{
					"label": "华为 Mate 20",
					"value": "Mozilla/5.0 (Linux; Android 9; HUAWEI Mate 20 Build/HUAWEIMate20) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/80.0.3987.149 Mobile Safari/537.36",
				},
				{
					'label': "荣耀9",
					"value": "Mozilla/5.0 (Linux; Android 7.0; STF-AL10 Build/HUAWEISTF-AL10; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/53.0.2785.49 Mobile MQQBrowser/6.2 TBS/043508 Safari/537.36 V1_AND_SQ_7.2.0_730_YYB_D QQ/7.2.0.3270 NetType/4G WebP/0.3.0 Pixel/1080"
				},
				{
					"label": "vivo Y13iL",
					"value": "Mozilla/5.0 (Linux; Android 4.4.2; vivo Y13iL Build/KTU84P) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/37.0.0.0 Mobile Safari/537.36"
				},
				{
					"label": "vivo Y13T",
					"value": "Mozilla/5.0 (Linux; Android 5.1.1; vivo Y13T Build/JDQ39) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/37.0.0.0 Mobile Safari/537.36"
				}
			],
			setting: {...storeConfig.setting},
			betTypeList: [
				{
					'label': '全场让球',
					'value': 'concede_points',
					'checked': false,
				}
			],
		}
	},
	methods:{
		saveSetting(){
			let from = {...this.setting};
			
			for (let i=0;i<url_keys.length;i++) {
				let item = url_keys[i];
				let key = item.key;
				if(!from[key] || !validator.isURL(from[key].toString())) {
					this.$message.error(item.desc + "错误");
					return;
				}
			}
			
			for (let i=0;i<int_keys.length;i++) {
				let item = int_keys[i];
				let key = item.key;
				if(from[key] != 0 && !validator.isInt(from[key].toString())) {
					this.$message.error(item.desc + "错误");
					return;
				}
			}
			
			for (let i=0;i<number_keys.length;i++) {
				let item = number_keys[i];
				let key = item.key;
				if(from[key] != 0 && !validator.isInt(from[key].toString()) && !validator.isFloat(from[key].toString()) ) {
					this.$message.error(item.desc + "错误");
					return;
				}
			}
			this.$message.success("设置成功");
			storeConfig.updateSettingConfig({...from});
			
			ipcRenderer.send('updateUserAgent', from.bet_user_agent);
			
		}
	},
	created() {
		ipcRenderer.send('updateUserAgent', storeConfig.setting.bet_user_agent);
	}
}
</script>
<style scoped lang="scss">
.app-container {
	position: relative;
	padding-bottom: 100px;
}
.setting-button {
	border-top:1px solid #eaeefb;
	background-color: #fff;
	position: fixed;
	bottom:0;
	left:0;
	width: 100%;
	text-align: right;
	padding: 20px 40px;
}
.box-card-header {
	font-weight: bold;
}
</style>